<template>
<div >
  <el-dialog :visible.sync="dialogFormVisibleRegistered">
    <div class="registeredBox">
      <div class="registered">普通注册</div>
    </div>

    <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="77px" class="demo-ruleForm">
      <el-form-item label="账号:" prop="name">
        <el-input v-model="ruleForm.accnent" placeholder="请输入账号(6-20位,非纯数字)！"></el-input>
      </el-form-item>
      <el-form-item label="密码:" prop="name">
        <el-input v-model="ruleForm.passWord"  placeholder="请输入你的密码(6-20位,非汉字)！"></el-input>
      </el-form-item>
      <el-form-item label="确认密码:" prop="name">
        <el-input v-model="ruleForm.name" placeholder="请再次输入你的密码！"></el-input>
      </el-form-item>
      <el-form-item label="昵称:" prop="name">
        <el-input v-model="ruleForm.nickName" placeholder="请输入你的昵称！"></el-input>
      </el-form-item>
      <el-form-item label="手机号码:" prop="name">
        <el-input placeholder="请输入手机号" v-model="ruleForm.phoneNumber">
          <el-select v-model="select" slot="prepend" placeholder="+86">
            <el-option label="+86" value="1"></el-option>
          </el-select>
        </el-input>
      </el-form-item>
      <el-form-item label="验证码:" prop="name">
        <!-- <el-input v-model="ruleForm.phoneCode" placeholder="请输入验证码"></el-input> -->
            <div class="codes">
          <el-input placeholder="请输入验证码" v-model="ruleForm.code"></el-input>
          <el-button class="code" size="mini" type="primary" @click="getCodes" :disabled="disabled">{{getCodeVlue}}</el-button>
        </div>
      </el-form-item>
      <el-button type="primary" @click="getRegistered">注册</el-button>
      <div class="footer" @click="goLogin">去登录</div>
    </el-form>
  </el-dialog>
</div>
</template>

<script>
import {getRegisteredInterFace,getRegisterPhoneCode} from "../api/userCenter-api"

export default {
name: "Registered",
  data() {
    return {
      dialogFormVisibleRegistered: false,
      activeName: 'first',
      stateCode:0,
      getCodeVlue: "获取验证码",
      disabled: false,
      num: 60,
      ruleForm: {
        accnent: '',
        passWord:'',
        nickName:'',
        phoneNumber:"",
        phoneCode:'',
      },
      rules: {
        name: [
          { required: true, message: '请输入活动名称', trigger: 'blur' },
          
        ],
      },
     input1: '',
      input2: '',
      input3: '',
      select: ''
    };
  },
  methods: {
    
    goLogin(){
      this.$emit("goLoginInterface",this.stateCode++)
      this.dialogFormVisibleRegistered=false
    },
    getCodes(){
     
  // 请求验证码结束
  // 动态效果
      // 请求验证码开始
       
       if(this.ruleForm.phoneCode===''){
           this.$message({
          message:"请输入验证码",
          type: 'warning'
        });
       }else{
       getRegisterPhoneCode(this.ruleForm.phoneNumber).then(res=>{
       if(res.code===500){
           this.$message({
          message:res.msg,
          type: 'warning'
        });
       }else{
          let a1 = setInterval(() => {
        this.num--;
        this.disabled = true;

        this.getCodeVlue = `${this.num}秒后重试`;
      }, 1000);
      setTimeout(() => {
        clearInterval(a1);
        this.getCodeVlue = `获取验证码`;
        this.disabled = false;
        this.num=60
      }, 60000);
       }
      })
      }
    },
    getRegistered(){
getRegisteredInterFace(this.ruleForm.accnent,this.ruleForm.phoneCode,this.ruleForm.phoneNumber,this.ruleForm.passWord,this.ruleForm.nickname,).then(res=>{
  if(res.code===500){
    this.$message({
          message:res.msg,
          type: 'warning'
        });
  }else{
    this.$message({
          message:res.msg,
          type: 'success'
        });
      this.$emit("goLoginInterface",this.stateCode++)


  }
})
    }
  },
  props:{
    isShowLoginDiaLog:[Number,Boolean,Object],
  },
  watch: {
    isShowLoginDiaLog(){
      this.dialogFormVisibleRegistered=true
    }
  }
   
}
</script>

<style scoped lang="less">
/deep/.el-select .el-input {
    width: 80px;
  }
 /deep/.input-with-select .el-input-group__prepend {
    background-color: #fff;
  }
/deep/.el-dialog__header{
  padding:0;
}
/deep/.el-dialog{
  width:380px;
  height:573px;
  padding:20px 36px 24px 36px;
}
/deep/.el-dialog__body{
  padding:0;
}
.registeredBox{
  width:308px;
  height:57px;
}
.registered{
  width:154px;
  height:48px;
  border-bottom:2px solid #00cf8c;
  margin-left:80px;
  line-height:48px;
  color:#00cf8c;
}
/deep/.el-form .demo-ruleForm{
  padding-top:10px;
}
/deep/.el-form-item__label{
  padding:0;
}
/deep/.el-form-item__content{
  margin-left:80px;
  padding:3px 0;
}
/deep/.el-input__inner{
  height:32px;
}
/deep/.el-form-item__error{
  padding-top:0;
}
/deep/.el-dialog__body{
  padding-top:10px;
}
/deep/.el-button--primary {
  color: #FFF;
  background-color: #00cf8c;
  border-color: #00cf8c;
  &:hover{
    color:#fff;
    background-color:#23db9b ;
    border-color: #23db9b;
  }
  &:focus{
    color:#fff;
    background-color:#23db9b ;
    border-color: #23db9b;
  }
}
/deep/.el-button{
  padding:8px 125px;
}
.footer{
  display:flex;
  height:16px;
  justify-content: flex-end;
  margin-top:5px;
  &:hover{
    color:#23db9b;
  }
}
.el-select .el-input {
  width: 20px;
  background-color: white;
}
.input-with-select .el-input-group__prepend {
  background-color: white;
}
.codes{
  display:flex;
  justify-content: space-between;
}
/deep/.code{
  margin-left:10px;
  width:35px;
  font-size:14px;
}
/deep/.el-button--mini{
  padding:8px 50px;
  height:32px;
  margin-top:3px;
  span{
    margin-left:-33px;
  }
}
</style>